<template>
  <div class="app-container">
    <!--工具栏-->
    <div class="head-container">
      <!-- 搜索 -->
      <!-- <el-input v-model="query.prizeName" clearable placeholder="输入搜索内容" style="width: 200px;" class="filter-item"
        @keyup.enter.native="toQuery" />
      <el-select v-model="query.prizeType" clearable placeholder="奖品分类" class="filter-item" filterable
        style="width: 130px">
        <el-option v-for="item in optionsMetaShow" :disabled="item.disabled === 0" :value="item.id" :key="item.id"
          :label="item.title"></el-option>
      </el-select>
      <el-button class="filter-item" size="mini" type="success" icon="el-icon-search" @click="toQuery">搜索</el-button> -->
      <!-- 新增 -->
      <div style="display: inline-block;margin: 0px 2px;">
        <el-button class="filter-item" size="mini" type="primary" icon="el-icon-plus" @click="toAddURL">
          新增出行方式
        </el-button>
        <el-button type="danger" class="filter-item" size="mini" icon="el-icon-refresh" @click="toQuery">刷新</el-button>
        <el-button type="info" class="filter-item" size="mini" icon="el-icon-close" @click="reset">重置</el-button>
      </div>
    </div>
    <!--表单组件-->
    <!--表格渲染-->
    <el-table v-loading="loading" :data="data" size="small" style="width: 100%;">
      <el-table-column prop="id" width="140" label="出行ID">
      </el-table-column>
      <el-table-column prop="modeName" label="出行方式名称	">
      </el-table-column>
      <el-table-column prop="dayStartingPrice" label="白天起步价 (km/元)">
      </el-table-column>
      <el-table-column prop="dayCostPerKilometer" label="白天每公里费用 (km/元)">
      </el-table-column>
      <el-table-column prop="eveningStartingPrice" label="	晚上起步价 (km/元)">
      </el-table-column>
      <el-table-column prop="eveningCostPerKilometer" label="	晚上每公里费用 (km/元)">
      </el-table-column>
      <el-table-column prop="description" label="出行方式描述	"></el-table-column>
      <el-table-column prop="distanceCoverage" label="覆盖距离(km)">

      </el-table-column>
      <el-table-column prop="travelInstructions" label="出行方式说明">

</el-table-column>

      <el-table-column label="是否环保" align="center">
        <template slot-scope="scope">
          <div>
            <el-tag v-if="scope.row.isEnvironmentFriendly == 1" style="cursor: pointer" :type="''">环保</el-tag>
            <el-tag v-else style="cursor: pointer" :type=" 'info' ">不环保</el-tag>
          </div>
        </template>
      </el-table-column>
      <el-table-column label="是否可用" align="center">
        <template slot-scope="scope">
          <div>
            <el-tag v-if="scope.row.isShow == 0" style="cursor: pointer" :type="''">是</el-tag>
            <el-tag v-else style="cursor: pointer" :type=" 'info' ">否</el-tag>
          </div>
        </template>
      </el-table-column>




      <el-table-column  width="160" label="创建时间">
        <template slot-scope="scope">
          <span>{{ formatTimeTwo(scope.row.createTime) }}</span>
        </template>
      </el-table-column>
      <el-table-column label="操作" width="265px" align="center">
        <template slot-scope="scope">
          <el-button size="mini" type="primary" icon="el-icon-edit" @click="toUpdateURL(scope.row)">
            编辑
          </el-button>
          <el-popover :ref="scope.row.id" placement="top" width="180">
            <p>确定删除本条数据吗？</p>
            <div style="text-align: right; margin: 0">
              <el-button size="mini" type="text" @click="$refs[scope.row.id].doClose()">取消</el-button>
              <el-button :loading="delLoading" type="primary" size="mini"
                @click="subDelete(scope.row.id)">确定</el-button>
            </div>
            <el-button slot="reference" type="danger" icon="el-icon-delete" size="mini">删除</el-button>
          </el-popover>
        </template>
      </el-table-column>
    </el-table>
    <eForm ref="form" :is-add="isAdd" />

    <!--分页组件-->
    <el-pagination :total="total" :current-page="page + 1" style="margin-top: 8px;"
      layout="total, prev, pager, next, sizes" @size-change="sizeChange" @current-change="pageChange" />

  </div>
</template>

<script>
import initData from '@/mixins/crud'
import { delModes } from '@/api/technician'
import eForm from './form1'
import { formatTimeTwo } from '@/utils/index'

import '@riophae/vue-treeselect/dist/vue-treeselect.css'
import Treeselect from '@riophae/vue-treeselect'
export default {
  components: { Treeselect, eForm },
  mixins: [initData],
  data() {
    return {
      dropDownValue: '',
      optionsMetaShow: [
        {
          title: "实物", id: 1
        },
        {
          title: "优惠卷", id: 2
        },
        {
          title: "微信返现", id: 3
        },
      ],
      delLoading: false,
      query: {
        prizeName: '',
        prizeType: ''
      },
      isAttr: false,
    }
  },
  created() {
    this.$nextTick(() => {
      if (this.$route.params.id) {
        this.query.merId = this.$route.params.id
      }
      this.init().then(() => {

      })
    })
  },
  methods: {
    formatTimeTwo,
    reset() {
      this.query.prizeName = ''
      this.query.prizeType = ''
      this.toQuery()
    },
    toAddURL() {
      this.isAdd = true
      this.$refs.form.dialog = true
    },
    toUpdateURL(row) {
      this.isAdd = false
      this.$refs.form.dialog = true

      this.$refs.form.form = {
        id: row.id,
        costPerKilometer:row.costPerKilometer,//	每公里费用
        description:row.description,//	出行方式描述
        distanceCoverage:row.distanceCoverage,//	覆盖距离（单位：公里）
        isEnvironmentFriendly:row.isEnvironmentFriendly,	//是否环保(0:不环保，1：环保）
        isShow:row.isShow,//	是否可用（0：是，1：否）
        modeName:row.modeName,//	出行方式名称
        dayCostPerKilometer:row.dayCostPerKilometer,//白天每公里费用
        dayStartingPrice:row.dayStartingPrice,//白天起步价
        eveningCostPerKilometer:row.eveningCostPerKilometer,//	晚上每公里费用
        eveningStartingPrice:row.eveningStartingPrice,//晚上起步价
        travelInstructions:row.travelInstructions,//出行方式说明
      }
      console.log(this.$refs.form.form)
    },

    beforeInit() {

      this.url = 'api/yxTechnicianTravelModes'
      const sort = 'id,desc'
      this.params = { page: this.page, size: this.size, sort: sort }
      return true
    },
    subDelete(id) {
      console.log(id)
      this.delLoading = true
      let data = [id]

      delModes(data).then(res => {
        this.delLoading = false
        this.$refs[id].doClose()
        this.dleChangePage()
        this.init()
        this.$notify({
          title: '删除成功',
          type: 'success',
          duration: 2500
        })
      }).catch(err => {
        this.delLoading = false
        this.$refs[id].doClose()
        console.log(err.response.data.message)
      })
    },
  }
}
</script>

<style scoped></style>
